package com.collection.linkedlist;

import java.util.LinkedList;

public class LinkedListReplaceElementExample {
	public static void main(String[] args) {
		 
	    //create LinkedList object
	    LinkedList lList = new LinkedList();
	   
	    //add elements to LinkedList
	    lList.add("1");
	    lList.add("2");
	    lList.add("3");
	    lList.add("4");
	    lList.add("5");
	   
	    System.out.println("LinkedList contains : " + lList);
	   
	    /*
	     * To replace an element of LinkedList at specified index, use
	     * Object set(int index, Object element) method.
	     *
	     * It replaces specified element at specified index in the LinkedList and
	     * returns the element previously at the specified index.
	     */
	         
	     lList.set(3, "Replaced");
	     System.out.println("After replacing 4, LinkedList contains : " + lList);
	   
	   
	  }
}
